package sctu.edu.java.year2016.team07.huangsuixin.day20160605.chapter11_3;

/**
 * Created by Huang Suixin on 2016/6/5.
 */

import com.sun.org.apache.xpath.internal.SourceTree;

import java.util.Scanner;

/**
 * 3.创建Computer类，该类中有一个计算两个最大公约数的方法，
 * 如果向该方法传递负整数，该方法就会抛出自定义异常。
 */
public class Computer {
    private int maxCommenDivisor(int a,int b) throws MyException{
        if(a<0||b<0){
            throw new MyException();
        }
        while(a%b!=0){
            int temp = a%b;
            a = b;
            b = temp;
        }
        return b;
    }

    public static void main(String[] args) throws MyException {
        Scanner scan = new Scanner(System.in);
        System.out.print("输入一个数：");
        int a = scan.nextInt();
        System.out.print("输入另一个数：");
        int b = scan.nextInt();
        Computer test = new Computer();
        System.out.println("两数最大公约数是："+test.maxCommenDivisor(a,b));
    }
}
